import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/workspace',
    children: [{
      path: 'workspace',
      name: 'Workspace',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '工作台', icon: 'dashboard' }
    }]
  },
  // 用户管理
  {
    path: '/user',
    component: Layout,
    children: [
      {
        path: 'useritem',
        name: 'Useritem',
        component: () => import('@/views/user/index'),
        meta: { title: '用户管理', icon: 'form',  }
      }
    ]
  },
   // 政策订单
  {
    path: '/example',
    component: Layout,
    redirect: '/example/order',
    name: 'Example',
    meta: { title: '政策订单', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'order',
        name: 'Order',
        component: () => import('@/views/zhengce/jiaoyi'),
        meta: { title: '交易订单', icon: 'table' }
      },
      {
        path: 'travel',
        name: 'Travel',
        component: () => import('@/views/zhengce/luxing'),
        meta: { title: '旅行社', icon: 'tree' }
      }
    ]
  },
     // 景区门票
  {
    path: '/ticket',
    component: Layout,
    redirect: '/ticket/product',
    name: 'Ticket',
    meta: { title: '景区门票', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'product',
        name: 'Product',
        component: () => import('@/views/menpiao/product'),
        meta: { title: '组合产品', icon: 'table' }
      },
      {
        path: 'manage',
        name: 'Manage',
        component: () => import('@/views/menpiao/piaozhong'),
        meta: { title: '票种管理', icon: 'tree' }
      }
    ]
  },
   // 装备租赁
  {
    path: '/equip',
    component: Layout,
    redirect: '/equip/sort',
    name: 'Equip',
    meta: { title: '装备租赁', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'sort',
        name: 'Sort',
        component: () => import('@/views/zuli/fenlei'),
        meta: { title: '装备分类', icon: 'table' }
      },
      {
        path: 'control',
        name: 'Control',
        component: () => import('@/views/zuli/guanli'),
        meta: { title: '装备管理', icon: 'tree' }
      }
    ]
  },
  // {
  //   path: '/form',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'Form',
  //       component: () => import('@/views/form/index'),
  //       meta: { title: 'Form', icon: 'form' }
  //     }
  //   ]
  // },
  // 运营管理
   {
    path: '/yunying',
    component: Layout,
    redirect: '/yunying/scenic',
    name: 'Yunying',
    meta: {
      title: '运营管理',
      icon: 'nested'
    },
    children: [
      {
        path: 'scenic',
        component: () => import('@/views/yunying/menu1/index'), // Parent router-view
        name: 'Scenic',
        meta: { title: '景区管理' },
        children: [
          {
            path: 'menu1-1',
            component: () => import('@/views/yunying/menu1/menu1-1'),
            name: 'Menu1-1',
            meta: { title: '基本信息' }
          },
          {
            path: 'menu1-2',
            component: () => import('@/views/yunying/menu1/menu1-2'),
            name: 'Menu1-2',
            meta: { title: '售票点管理' },
            
          },
          {
            path: 'menu1-3',
            component: () => import('@/views/yunying/menu1/menu1-3'),
            name: 'Menu1-3',
            meta: { title: '检票点管理' }
          }
        ]
      },
      {
        path: 'rule',
        component: () => import('@/views/yunying/menu2/index'),
        name: 'Rule',
        meta: { title: '规则管理' },
        children: [
          {
            path: 'menu1-1',
            component: () => import('@/views/yunying/menu2/menu2-1'),
            name: 'Menu1-1',
            meta: { title: '核销规则' }
          },
          {
            path: 'menu1-2',
            component: () => import('@/views/yunying/menu2/menu2-2'),
            name: 'Menu1-2',
            meta: { title: '退改规则' },
      
          },
          {
            path: 'menu1-3',
            component: () => import('@/views/yunying/menu2/menu2-3'),
            name: 'Menu1-3',
            meta: { title: '通知规则' }
          }
        ]
      }
    ]
  },


 // 财务对账
  {
    path: '/money',
    component: Layout,
    redirect: '/money/tuipiao',
    name: 'Money',
    meta: { title: '财务对账', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'tuipiao',
        name: 'Tuipiao',
        component: () => import('@/views/caiwu/tuipiao'),
        meta: { title: '退票审核', icon: 'table' }
      },
      {
        path: 'tuikuan',
        name: 'Tuikuan',
        component: () => import('@/views/caiwu/tuikuan'),
        meta: { title: '退款审核', icon: 'tree' }
      }
    ]
  },
// 报表中心
  {
    path: '/excel',
    component: Layout,
    redirect: '/excel/xiaoshou',
    name: 'Excel',
    meta: { title: '报表中心', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'xiaoshou',
        name: 'Xiaoshou',
        component: () => import('@/views/baobiao/xiaoshou'),
        meta: { title: '销售流水', icon: 'table' }
      },
      {
        path: 'tongji',
        name: 'Tongji',
        component: () => import('@/views/baobiao/tongji'),
        meta: { title: '统计分析', icon: 'table' }
      },
      {
        path: 'zulin',
        name: 'Zulin',
        component: () => import('@/views/baobiao/zuli'),
        meta: { title: '租赁系统', icon: 'table' }
      },
    ]
  },


  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
